package com.entity;

import lombok.Data;
import lombok.experimental.Accessors;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 统一返回格式
 * @author: GuoTong
 * @createTime: 2021-06-23 10:28
 * @since JDK 1.8 OR 11
 **/

@Data
@Accessors(chain = true)
public class RespObject {
    private final static String SUCCESS = "成功";
    private final static int SUCCESS_CODE = 200;
    private final static String FAIL = "失败";
    private final static int FAIL_CODE = 500;
    private int code;
    private String msg;
    private Object data;

    public static RespObject respOk() {
        return new RespObject().setCode(200).setMsg(SUCCESS);
    }

    public static RespObject respOk(Object data) {
        return new RespObject().setCode(200).setMsg(SUCCESS).setData(data);
    }

    public static RespObject respOk(int code, String msg) {
        return new RespObject().setCode(code).setMsg(msg);
    }

    public static RespObject respNo(int code, String msg) {
        return new RespObject().setCode(code).setMsg(msg);
    }


    public static RespObject respNo() {
        return new RespObject().setCode(500).setMsg(FAIL);
    }

    public static RespObject respNo(String msg) {
        return new RespObject().setCode(500).setMsg(msg);
    }

    public static Map<String, Object> respLogin(String token, UserTable userTable) {
        Map<String, Object> data = new HashMap<>();
        data.put("token", token);
        data.put("code", SUCCESS_CODE);
        data.put("data", userTable);
        data.put("msg", "登录成功返回结果");
        return data;
    }


}
